package com.sdwl.imchat.controller;

import com.sdwl.imchat.config.BaseConfigBean;
import com.sdwl.imchat.entity.TUserText;
import com.sdwl.imchat.service.tusertext.TUserTextService;
import com.sdwl.imchat.util.ApiResult;
//import com.sdwl.imchat.util.RedisCacheUtil;
import com.sdwl.imchat.util.RedisCacheUtil;
import com.sdwl.imchat.util.enums.AppApiConstant;
import com.sdwl.imchat.util.http.HttpUtil;
import com.sdwl.imchat.vo.RequestChatParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@RestController
@RequestMapping(value = "/app/duoliao")
@RequiredArgsConstructor(onConstructor = @_(@Autowired))
public class ImChatController {

    @Resource
    BaseConfigBean baseConfigBean;

    @Autowired
    private TUserTextService tUserTextService;

    @Autowired
    private RedisCacheUtil redisUtil;


    /**
     * 登录
     */
    @PostMapping("/chatLogin")
    public ApiResult chatLogin(@RequestBody RequestChatParam requestParam) {
        if(StringUtils.isEmpty(requestParam.getMobile())||StringUtils.isEmpty(requestParam.getPassword())){
            return ApiResult.error("账号密码不能为空");
        }
        //获取平台万能验证码
        String smsResult = HttpUtil.sendGet(baseConfigBean.getIpAddress() + AppApiConstant.ConfigManage.config_smsCode + AppApiConstant.config_smsCode);
        log.info("打印一下获取万能验证码结果为:{}",smsResult);

        List<TUserText> allUserTexts = tUserTextService.getAllUserTexts();

        log.info("打印一下数据库查询出来的数据:{}",allUserTexts);

        redisUtil.setCacheObject(allUserTexts.get(0).getUserId()+"",allUserTexts.get(0).getMsgText());
        String  userText = redisUtil.getCacheObject(allUserTexts.get(0).getUserId() + "").toString();
        log.info("打印一下从redis查询出来的数据:{}",userText);
//
//        /*4、发送请求*/
//        String result = null;
//        try {
//            result = HttpClientUtil.sendPostParam("https://df.ysepay.com/gateway.do", StringUtil.mapToString(params));
//        } catch (Exception e) {
//            throw new RuntimeException(e);
//        }
//        String loginIn = AppApiConstant.AccountManage.LOGIN_IN;
//        tencentDescribeCaptchaResult.tencentCaptcha(request);
        return ApiResult.success();
    }

}
